import { Component, OnInit, ViewChild } from '@angular/core';
import { kMaxLength } from 'buffer';
import { CoreComponent } from 'pengesoft-ng-lib';
import { NzTableModule } from 'ng-zorro-antd/table';
import {
  FormBuilder,
  FormControl,
  FormGroup,
  ValidationErrors,
  Validators,
} from '@angular/forms';
import { Observable, Observer } from 'rxjs';
import {
  NzFormatEmitEvent,
  NzTreeComponent,
  NzTreeNodeOptions,
} from 'ng-zorro-antd/tree';

interface ItemData {
  id: number;
  upName: string;
  name: string;
  age: number;
  department: string;
  post: string;
  phone: string;
  role: string;
  lastLogin: string;
  password: string;
  dot: boolean;
}
@Component({
  selector: 'app-user-management',
  templateUrl: './user-management.component.html',
  styleUrls: ['./user-management.component.less'],
})
export class UserManagementComponent implements OnInit {

  constructor(private fb: FormBuilder) { }
  inputValue?: string; // 搜索框值
  options: string[] = []; // 自动填充内容
  i = 0;
  editId: string | null = null;
  // 修改角色名 模态框start
  visible = false;
  listOfData: ItemData[] = [];
  switchValue = false;
  validateForm!: FormGroup;
  onInput(event: Event): void {
    const value = (event.target as HTMLInputElement).value;
    // this.options = value ? [value, value + value, value + value + value] : [];
  }
  // 新增用户打开抽屉
  open(): void {
    this.visible = true;
  }
  // 新增用户关闭抽屉
  close(): void {
    this.visible = false;
  }

  // 删除用户
  deleteRow(id: string): void {
    this.listOfData = this.listOfData.filter((d) => d.id !== Number(id));
  }

  submitForm(): void {
    // tslint:disable-next-line: forin
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty();
      this.validateForm.controls[i].updateValueAndValidity();
    }
  }

  // 重置密码
  resetPaW(id: string): void {
    // this.paw = '123'
    console.log(123);
  }
  ngOnInit(): void {
    // 死数据
    this.listOfData = new Array(15).fill(0).map((_, index) => {
      return {
        id: index,
        name: `Edward King ${index}`,
        age: 32,
        address: `London, Park Lane no. ${index}`,
        upName: `kangjang. ${index}`,
        department: 'IT部门',
        post: '前端',
        phone: '123456',
        role: '超级管理员',
        lastLogin: '2020-12-05',
        password: '1131',
        dot: false,
      };
    });
    // 死数据
    this.validateForm = this.fb.group({
      upName: [null, [Validators.required]],
      name: [null, [Validators.required]],
      password: [null, [Validators.required]],
      id: [null, [Validators.required]],
    });
  }
}
